from Hogwarts.Homeworks.hw0718.api.wework import WeWork


class ApiContactTag(WeWork):

    def create(self, tag_name, tag_id=None):
        data = {
            "method": 'post',
            "url": f"{self.base_url}/tag/create",
            "params": {"access_token": self.token},
            "json": {
                "tagname": tag_name
            }
        }

        return self.do_request(data)

    def update(self, tag_id: int, tag_name: str):
        data = {
            "method": 'post',
            "url": f"{self.base_url}/tag/update",
            "params": {"access_token": self.token},
            "json": {
                "tagid": tag_id,
                "tagname": tag_name
            }
        }
        return self.do_request(data)

    def delete(self, tag_id: int):
        data = {
            "method": 'get',
            "url": f"{self.base_url}/tag/delete",
            "params": {"access_token": self.token, "tagid": tag_id},
        }
        return self.do_request(data)

    def query(self):
        data = {
            "method": 'get',
            "url": f"{self.base_url}/tag/list",
            "params": {"access_token": self.token},
        }
        return self.do_request(data)

    def check_tag_ids(self):
        resp = self.query()
        return [item['tagid'] for item in resp.json().get('taglist')]

    def check_tag_names(self):
        resp = self.query()
        return [item['tagname'] for item in resp.json().get('taglist')]